// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __NC_EXP_ENTRY_H__
#define __NC_EXP_ENTRY_H__

#include <cstdio>
#include <assert.h>
#include "Types.hpp"

namespace ninf {
namespace gen {

class ExpEntry {
public:
	ninf::lib::ExpEntryTag tag;
  int           val;

  // CONSTRUCTORS 
  ExpEntry(){}

  ExpEntry(int      i): tag( ninf::lib::VALUE_CONST), val(i){}

  ExpEntry(ninf::gen::ExpOp op): tag( ninf::lib::VALUE_OP) , val((int)op){}

  ExpEntry(ninf::lib::ExpEntryTag tag, int val): tag(tag), val(val) {}


  // STATIC FUNCTION for CONSTRACT
  static ExpEntry inArg(int i){ return ExpEntry(ninf::lib::VALUE_IN_ARG, i);}

  static ExpEntry endOf()     { return ExpEntry(ninf::lib::VALUE_END_OF_OP, 0);}

  static ExpEntry none()      { return ExpEntry(ninf::lib::VALUE_NONE, 0);}

  // write out declaration string 
  void writeDeclaration(FILE * fp);

  int evaluate(int * iArgs, int len){
    assert(tag == ninf::lib::VALUE_CONST || tag ==  ninf::lib::VALUE_IN_ARG);
    if (tag ==  ninf::lib::VALUE_CONST)
      return val;
    if (tag ==  ninf::lib::VALUE_IN_ARG){
      assert(len > val);
      return iArgs[val];
    }
    // never comes
    return -1;
  }

};
}
}
#endif
